<template>
    <div class="audit_records">
        <!--信审结论-->
        <el-table class="loan_history_table" max-height="320" :data="tableData" style="width: 100%">
            <el-table-column align="left" :label="$t('common.innerOrderId')" prop="orderId"></el-table-column><!--内部订单号-->
            <el-table-column align="left" :label="$t('common.operatingTime')"><!--操作时间-->
                <template slot-scope="scope">{{ scope.row.addTime | formatDate('yyyy-MM-dd hh:mm:ss') }}</template>
            </el-table-column>
            <el-table-column align="left" :label="$t('audit.resultType')"><!--结果类型-->
                <template slot-scope="scope">{{scope.row.type | resultTypeFilter}}</template>
            </el-table-column>
            <el-table-column align="left" prop="auditorName" :label="$t('audit.firstReviewer')"></el-table-column><!--初审员-->
            <el-table-column align="left" prop="result" :label="$t('audit.resultAndReason')"><!--结论及原因-->
                <template slot-scope="scope">{{scope.row.result | resultSwitch}}</template>
            </el-table-column>
            <el-table-column align="left" prop="reasonCode" :label="$t('audit.reasonCode')"></el-table-column><!--原因码-->
            <el-table-column align="left" prop="otherRemark" :label="$t('common.remark')"></el-table-column><!--备注-->
        </el-table><!--end table-->
        <pagination @pageChange="pageChange" :page="page"></pagination>
    </div>
</template>

<script>
    import Pagination from '@/components/pagination';
    import mixin from '@/service/mixin';

    let that = null;
    export default {
        name: 'auditRecords',
        components: {
            Pagination
        },
        mixins: [mixin],
        props: {
            updateType: {
                type: String
            }
        },
        data() {
            return {
                userId: '',
                orderId: ''
            };
        },
        watch: {
            updateType(val) {
                if (val === 'auditRecords') {
                    this.page.currentPage = 1;
                    this.getTableData();
                }
            }
        },
        methods: {
            getTableData(page = this.page) {
                const params = {
                    userId: this.userId,
                    page: {
                        pageNo: page.currentPage,
                        pageSize: this.page.pageSize
                    }
                };
                this.$api.audit.auditOpList(params).then((res) => {
                    const {status, data, error} = res;
                    if ('1' === status && '00000000' === error) {
                        this.tableData = data.resultList;
                        this.page.recordsTotal = data.page.totalRecord || data.page.totalCount;
                        if (this.updateType === 'auditRecords') {
                            this.$emit('updateOver');
                        }
                    }
                });
            }
        },
        // rcaStatus PRE_ADMITTANCE 待准入  ADMITTANCE_SUCCESS 准入成功  AUTO_AUDIT_SUCCESS 自核通过 ADMITTANCE_REFUSE 准入失败
        // status 待审核 BORROW_AUDIT,初审通过 AUDIT_SUCCESS,复核状态：AUDIT_CHECK,终审通过 LAST_AUDIT_SUCCESS,信审拒绝 AUDIT_REFUSE
        filters: {
            resultTypeFilter(type) {
                switch (type) {
                    case 'FIRST_AUDIT':
                        return that.$t('audit.firstAudit'); // 初审
                    case 'LAST_AUDIT':
                        return that.$t('audit.lastAudit'); // 终审
                    case 'RE_AUDIT':
                        return that.$t('audit.recheckAudit'); // 复核
                    default:
                        return '';
                }
            },
            resultSwitch(result) {
                switch (result) {
                    case 'PRE_ADMITTANCE':
                        return that.$t('audit.willEntrance'); // 待准入
                    case 'ADMITTANCE_SUCCESS':
                        return that.$t('audit.entranceSucc'); // 准入成功
                    case 'AUTO_AUDIT_SUCCESS':
                        return that.$t('audit.AUTO_AUDIT_SUCCESS'); // 自核通过
                    case 'ADMITTANCE_REFUSE':
                        return that.$t('audit.entranceFail'); // 准入失败
                    case 'BORROW_AUDIT':
                        return that.$t('audit.willAudit'); // 待审核
                    case 'AUDIT_SUCCESS':
                        return that.$t('audit.firstAuditPass'); // 初审通过
                    case 'AUDIT_CHECK':
                        return that.$t('audit.recheckState'); // 复核状态
                    case 'LAST_AUDIT_SUCCESS':
                        return that.$t('audit.lastAuditPass'); // 终审通过
                    case 'AUDIT_REFUSE':
                        return that.$t('audit.auditRefuse'); // 信审拒绝
                    default:
                        return '';
                }
            }
        },
        created() {
            if (this.$route.params.id) {
                this.userId = this.$route.params.id;
                this.orderId = this.$route.params.orderId;
                this.page.pageSize = 4;
                this.getTableData();
            }
            that = this;
        },
    };
</script>

<style scoped>

</style>
